package com.goal98.team.services

import com.goal98.team.domain.Person
import com.goal98.grails.plugin.account.domain.Account

class PlayerService {

    boolean transactional = true

    def accountService

    def credit(Person person, BigDecimal amount, String description) {
        Account playerAccount = person.account
        Account teamAccount = person.team?.account

        accountService.credit(playerAccount, amount, description)
        if (teamAccount){
            accountService.credit(
                    teamAccount,
                    amount,
                    "${person.username}--${person.userRealName} | ${description}")
        }

    }

    def debit(Person person, BigDecimal amount, String description) {

        if(!person.account){
            person.account = new Account(balance:0, reference:person.username)
        }

        Account playerAccount = person.account
        accountService.debit(playerAccount, amount, description)

    }
}
